<template>
<section id="list" class="padding20">
<el-row :gutter="20">
	<el-form ref="form" label-width="70px">
		<el-col :span="24">
			<el-form-item label="员工姓名" class="mt">
				<el-input v-model="user.name" placeholder="请输入真实姓名"></el-input>
			</el-form-item>
		</el-col>
		<el-col :span="24">
			<el-form-item label="员工性别">
				<el-radio-group v-model="user.sex">
					<el-radio label="1">男</el-radio>
					<el-radio label="0">女</el-radio>
				</el-radio-group>
			</el-form-item>
		</el-col>
		<el-col :span="24">
			<el-form-item label="员工帐号">
				<el-input v-model="user.username" placeholder="请输入前台账号(手机号)"></el-input>
			</el-form-item>
		</el-col>
		<el-col :span="24">
			<el-form-item label="所属职位">
				<el-input v-model="pname" placeholder="请选择所属职位" disabled>
					<el-button slot="append" icon="search" @click="selzhi"></el-button>
				</el-input>
			</el-form-item>
		</el-col>
		<el-col :span="24">
			<el-form-item label="所属职称">
				<el-select v-model="user.zhichengid" class="width" placeholder="请选择所属职称">
					<el-option v-for="z in zlist" :label="z.name" :value="z.id" :key="z.id"></el-option>
				</el-select>
			</el-form-item>
		</el-col>
		<el-col :span="24">
			<el-form-item label="员工描述">
				<el-input type="textarea" v-model="user.remarks" placeholder="请输入员工描述"></el-input>
			</el-form-item>
		</el-col>
		<el-col :span="24">
			<el-form-item label="管理层">
				<el-switch v-model="user.ismanage" on-text="是" off-text="否"></el-switch>
			</el-form-item>
		</el-col>
	</el-form>
</el-row>
</section>
</template>
<script>
import C from '#/src/common/common.js'
import userAdduser from '#/src/organization/userAdduser.js'
export default {
    name: 'userAdduser',
    data () {
        return {
            user: {
                id: 0,
                name: '',
                sex: '0',
                username: '',
                positionid: '',
                zhichengid: '',
                ismanage: false,
                remarks: '',
            },
            pname: '',
            zlist: []
        }
    },
    async mounted () {
        let row = C.getDatas()
        console.log(row)
        if (row) {
            let row = row
            this.user.id = row.id
            this.user.name = row.name
            this.user.sex = row.sex.toString()
            this.user.username = row.username
            this.user.positionid = row.positionid
            this.user.zhichengid = row.zhichengid
            this.user.ismanage = row.ismanage ? true : false
            this.user.remarks = row.remarks
            this.pname = row.pname
            let data = await userAdduser.getPlist({ id: row.positionid }, 'post')
            if (data) this.zlist = data
        }
    },
    methods: {
        async selzhi () {
            let res = await C.openBrowserWindow('/html/organization/appuser/user_selectzhiwei.html', {}, { width: 400, height: 800 })
            if (res) {
                this.user.positionid = res.id
                this.pname = res.name
                let data = await userAdduser.getPlist({ id: res.id }, 'post')
                if (data) this.zlist = data
            }
        },
        async callSubmit (index) {
            if (!(/^[\u4e00-\u9fa5]{2,4}$/.test(this.user.name))) {
                C.error('姓名格式不正确！')
                return false
            } else if (!(/^1[345678]\d{9}$/.test(this.user.username))) {
                C.error('手机格式不正确！')
                return false
            } else if (this.user.positionid == '') {
                C.error('请选择职位！')
                return false
            } else if (this.user.zhichengid == '') {
                C.error('请选择职称！')
                return false
            }
            this.user.ismanage = this.user.ismanage ? 1 : 0
            let aaa = false
            this.zlist.forEach((res) => {
                if (res.id === this.user.zhichengid) {
                    aaa = true
                    return aaa
                }
            })
            if (aaa) {
                let data = await userAdduser.getAddedit(this.user, 'post')
                if (data) {
                    parent.this.getList()
                    parent.layer.close(index)
                    parent.layer.msg(data.data, { icon: 1, time: 1000 })
                }
            } else {
                C.error('请选择对应职位的职称！')
                return false
            }
        },
        close () {
            C.closeBrowserWindow()
        }
    }
}
</script>
<style>
.padding20{
    padding: 20px;
}
</style>
